
#include"graphics.h"

//*************************************继续游戏



extern WINDOW* g_win;
extern POINT* head;
extern int count;
extern POINT cursor;
void GOON()
{
	//POINT cursor = {15,40,NULL};			//定义一个光标初始化
	int getc;
	while(1)
	{
		clear_screen(0,0,COLS,LINES);		//清屏
		
		drawChessboard();				//画棋盘
		dsphelp();
		drawCursor(cursor);				//画光标
		
		drawChess(head);				//画棋子
	
		wrefresh(g_win);				//刷新窗口，显示窗口的最新变化
		getc=readkey();
		switch(getc)
		{
			case KEYUP:
				if(cursor.x > X_START)
					(cursor.x)-=LENGTH;
                            else if(cursor.x=X_START)
                                   (cursor.x)=35;
				break;
			case KEYDOWN:
				if(cursor.x < X_END)
					(cursor.x)+=LENGTH;
                            else if(cursor.x=X_END)
                                   (cursor.x)=7;
				break;
			case KEYLEFT:
				if(cursor.y > Y_START)
					(cursor.y)-=WIDTH;
                           else if(cursor.y=Y_START)
                                   (cursor.y)=66;
				break;
			case KEYRIGHT:
				if(cursor.y < Y_END)
					(cursor.y)+=WIDTH;
                            else if(cursor.y=Y_END)
                                   (cursor.y)=10;
				break;
			default:
				if(getc == 'q')		//判断为悔棋
					delChess(head);
				else if(getc == ESC)		//判断为ESC退出人人对战
					return;
				else if(getc == SPACE)	//判断如果为空格下子
				{
                                    int tmp=count;
					addChess(cursor,head);
					if(judgeVictor(head))//判断输赢
					{
						//POINT* tmp = head;
						//while(tmp != NULL)	//释放栈
						//{	
						//	tmp=tmp->next;
						//	free(head);
						//	head = tmp;
						//	
						//}
						count = 0;		//棋子数目初始化为0
						return;
					}
                                   if(tmp != count)
				        {
						computerStep(head);		
					}					
                                  if(judgeVictor(head))
						return;
					
				}

				 else if(getc=='r')
                               {  
                             //try  successfual!!!!............. 
                             computerStep(head);
                             if(judgeVictor(head))
			         return;
                
                             clear_screen(0,0,COLS,LINES);		//清屏
		
		             drawChessboard();				//画棋盘
		             dsphelp();
    
		             drawCursor(cursor);			       //画光标
		   
		             drawChess(head);				//画棋子
	
		             wrefresh(g_win);
                             sleep(0.5);                          
                           computerStep(head);
                            if(judgeVictor(head))
			         return;
                                    
                              }
			    break;
			
		}
	}
}
